// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import App from './App'
import router from './router'
import VueLazyload from 'vue-lazyload'
import store from './store/index'
import './config/index'
require('./assets/style/index.css')
Vue.config.productionTip = false

Vue.use(Vuex)
Vue.use(VueLazyload)

// 商品价格处理
Vue.filter("allPrice", function(val) {
	let len=val.toString().split(".")
	if(len.length>1){
	let date=len[1].length
	if(date==0){
	  return val+'.00'
	}else if(date==1){
	  return val+'0'
	}else{
	  return val
	}
	}else{
	return val+'.00'
	}
});

// 图片缓加载
Vue.use(VueLazyload, {
  preLoad: 1.3,
  error: 'dist/images/load.gif',
  loading: 'dist/images/load.gif',
  attempt: 1,
  listenEvents: [ 'scroll' ]
})

/*router.beforeEach(function (to, from, next) {
	store.commit('updateLoadingStatus', {isLoading: true})
	next()
})*/

/*router.afterEach(function (to) {
	store.commit('updateLoadingStatus', {isLoading: false})
	document.documentElement.scrollTop = document.body.scrollTop =0;
})*/

router.beforeEach((to,from,next) => {
    if(to.matched.some( m => m.meta.auth)){
        // 对路由进行验证
        if(store.state.login) { // 已经登陆
          	next()
        }else{
            store.state.loginbg=true //提示用户登录
          }
    }else{
      next()
    }
    document.documentElement.scrollTop = document.body.scrollTop =0;
})

router.afterEach(function (to) {
	document.documentElement.scrollTop = document.body.scrollTop =0;
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
